var express = require('express'),
  router = express.Router(),
  path = require('path');
var fs = require('fs'),
  bodyParser = require('body-parser'),
  multiparty = require('multiparty'),
  util = require('util'),
  basic = require('../../basicmodule/basic.js');

module.exports = function (app) {
  app.use('/', router);
};

var utils = require('../tool/Utils.js')

const DIRPATH = 'freedom' + utils.format + 'upload' + utils.format;

router.get('/delete.html', function (req, res, next) {
  var fileName = basic.getFilePath(DIRPATH) + req.body.file_name;
  utils.deleteall(fileName);

  res.redirect('/index.html');
});


router.post('/delete.html', function (req, res) {
  var fileName = basic.getFilePath(DIRPATH) + req.body.file_name;
  utils.deleteall(fileName);
  res.send(basic.getFileinfos(DIRPATH));
});

router.post('/deleteall.html', function (req, res) {

  var filePath = basic.getFilePath("freedom/upload");
  utils.deleteall(filePath);


  fs.mkdir(filePath, function (error) {
    if (error) {
      console.log(error);
      return false;
    }
    console.log('创建目录成功');
  });

  res.end();

});




